package com.cloud.shopping.search.controller;

import com.cloud.shopping.search.model.SeckillGoodsEs;
import com.cloud.shopping.search.service.SeckillGoodsSearchService;
import com.cloud.shopping.tool.RespResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author John.zhang
 * @version Id: SeckillGoodsSearchController, v 1.0 2021/1/8 11:30 ZhiYong Exp $
 */

@RestController
@RequestMapping(value = "/seckill/goods")
public class SeckillGoodsSearchController {

    @Resource
    private SeckillGoodsSearchService seckillGoodsSearchService;

    /**
     * 将秒杀商品导入索引库
     */
    @PostMapping(value = "/add")
    public RespResult add(@RequestBody SeckillGoodsEs seckillGoodsEs) {
        seckillGoodsSearchService.add(seckillGoodsEs);
        return RespResult.ok();
    }

    /**
     * 搜索商品数据
     * @param acid acid
     * @return RespResult
     */
    @GetMapping(value = "/search")
    public RespResult<List<SeckillGoodsEs>> list(@RequestParam("acid")String acid){
        //根据活动ID搜索
        List<SeckillGoodsEs> seckillGoodsEsList =  seckillGoodsSearchService.search(acid);
        return RespResult.ok(seckillGoodsEsList);
    }

}
